//
//  GYDiscoverViewController.swift
//  Swift-sina
//
//  Created by gaoyanyun on 16/5/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
private let CZDiscoverCellID = "CZDiscoverCellID"
class GYDiscoverViewController: GYRootViewController{

    override func viewDidLoad() {
        //设置刷新控件
        setupRefreshControl()
        
        super.viewDidLoad()
   //注册cell
        tableView.registerClass(UITableViewCell.self , forCellReuseIdentifier: CZDiscoverCellID)
        visitorView?.setupInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        
    }
    override func loadData() {
        refreshControl.beginRefreshing()
        //延迟刷新
        let when = dispatch_time(DISPATCH_TIME_NOW, Int64 (Double(NSEC_PER_SEC) * 1.0))
            
        dispatch_after(when , dispatch_get_main_queue()) {() -> Void in
            
            self.dataCount += 10
            
            //结束刷新
            self.refreshControl.endRefreshing()
            self.pullupView.stopAnimating()
            
           self.tableView.reloadData()
        }
        
       
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
   //定义一个私有属性 
    private var dataCount = 0
}

//数据源方法
extension GYDiscoverViewController{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataCount
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(CZDiscoverCellID, forIndexPath: indexPath)
        
        cell.textLabel?.text = "\(indexPath.row)"
        
        return  cell
    }
}
